# app/utils/decrpy.py
from Crypto.PublicKey import RSA
from Crypto.Cipher import PKCS1_v1_5
from Crypto.Cipher import PKCS1_OAEP
from Crypto.Random import get_random_bytes
import base64

with open('private.pem', 'rb') as f:
    private_key = f.read()
    # print(private_key)
    f.close()


class Rsa:
    def __init__(self):
        self.private_key = private_key

    def decrypt_message(self, ciphertext):
        key = RSA.import_key(self.private_key)
        cipher = PKCS1_v1_5.new(key)
        message = cipher.decrypt(base64.b64decode(ciphertext), None)
        return message.decode()